<script setup>
import {ref} from 'vue'
import PageContainer from '@/components/PageContainer.vue'
import { useUserStore } from '@/stores'
import { userUpdateUserInfoService } from '@/api/user'
import { ElMessage } from 'element-plus'
const {
  userInfo: { username, nickname, email, id },
  getUserInfo
} = useUserStore()

const userInfo = ref({ username, nickname, email, id })

//个人基本资料表单数据的校验规则
const rules = ref({
  nickname:[
    {required:true,message:'请输入用户名',trigger:'blur'}
  ],
  email:[
    {required:true,message:'请输入邮箱',trigger:'blur'}
  ]
})
const onUpateUserInfo = async ()=>{

  const res = await userUpdateUserInfoService(userInfo.value)
  //修改本地的用户数据
  await getUserInfo()
  ElMessage.success(res.data.message)

}
</script>
<template>
  <page-container title="基本资料">
    <el-row>
      <el-col :span="12" :offset="1">
        <el-form size="large" :rules="rules" :model="userInfo">
          <el-form-item label="登录名称" style="margin-left: 10px;">
            <el-input disabled v-model="userInfo.username"></el-input>
          </el-form-item>
          <el-form-item label="用户昵称" prop="nickname">
            <el-input v-model="userInfo.nickname"></el-input>
          </el-form-item>
          <el-form-item label="用户邮箱" prop="email">
            <el-input v-model="userInfo.email"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" style="margin-left: 80px;" @click="onUpateUserInfo">提交修改</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </page-container>
</template>
